import { Directive,  ElementRef, Input, Output, EventEmitter } from '@angular/core';

@Directive({
  selector: '[appBtnPermiss]'
})
export class BtnPermissDirective {

  @Input() permissId: string;
  @Input() type: boolean;

  private session = sessionStorage;
  private resourceInfo = JSON.parse(this.session.getItem('resources'));

  constructor(private el: ElementRef) {
  }

  ngOnInit(): void {
    this.btnPermiss() ? '' : this.el.nativeElement.style.display = 'none';
  }

  btnPermiss(): boolean{
    for(let i = 0; i < this.resourceInfo.length; i++) {
      if(this.type && this.type == true) {
        return false;
      }
      if(this.resourceInfo[i]['resourcePermission'] === this.permissId) {
        return true;
      }
    }
    return false;
  }

}
